package com.ming.rabbitmq.producer.workqueue;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 工作队列-发送消息
 */
public class Main {
    public static void main(String[] args) throws IOException, TimeoutException {
        // 创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("119.91.238.104");
        factory.setPort(5672);
        factory.setVirtualHost("/workqueue");
        factory.setUsername("admin");
        factory.setPassword("admin");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("work_queue",true,false,false,null);

        for (int i = 0; i <= 10; i++) {
            String message = "workqueue...";
            /**
             * 交换机名称,这里使用默认的 ""
             * 路由名称
             * 配置信息
             * 发送的消息
             */
            channel.basicPublish("","work_queue",null,message.getBytes());
        }
        channel.close();
        connection.close();
    }
}
